Learning Objectives

After completing this lesson, you’ll be able to:

Resources

Custom Transformer Input/Output Ports

Like a normal FME transformer, a custom transformer has a number of input and output ports:

Custom transformer input and output ports

These input and output ports are defined by input/output objects in the custom transformer definition itself:

Ports defined by input and output objects in the custom transformer

Renaming Ports

The first thing to know is that these input/output objects can be renamed, in order that the transformer ports get named appropriately. You can either double-click the object, choose Rename from the context menu, or press F2, in order to rename the object.

For example, here the user pressed F2 and renames the input port from StringConcatenator_Input to simply Input:

Renaming a custom transformer port

Renaming the input and output ports is useful for making the custom transformer intentions more explicit; for instance, helping the user to understand what data type is required as input.

For example, after editing the transformer might look like this:

A custom transformer with edited ports

Note

Here the user simply renamed the input port to Input. Renaming it to "Strings", "Lines", or "Raster" (for example) would help guide other users of the transformer as to what data is required.

However, they did rename the output port to illustrate the type of data that will emerge.

Adding or Removing Ports

Besides renaming ports, it is also possible to add new ports to a custom transformer.

To do so simply select Transformer Input (or Output) from either the menubar or the canvas context (right-click) menu:

Adding input ports

For example, here a user has ports to handle two streams of input data and two streams of output (one port for the required output, another that handles rejected features:

Custom transformer with two streams of input and output data

This means that each instance of the custom transformer has two input and two output ports:

Edited custom transformer with two input and output ports

Exercise

You are continuing to work with your colleague who created a workspace that calculates the population density for neighborhoods in the city of Vancouver.

You turned their workspace into a custom transformer for reuse in the last exercise. Now you need to show how to use it multiple times and apply edits to its definition.

1) Start Workbench

Open the starting workspace in FME Workbench (2023.2 or later).

2) Duplicate Custom Transformer

Notice that we started with two ExpressionEvaluators and now have one ExpressionEvaluator and one custom transformer. Let's place another instance of the custom transformer in place of the ExpressionEvaluator.

Click on the ExpressionEvaluator_2011 and press the delete key to delete it.

Click on the DensityEvaluator custom transformer and press Ctrl+D (or right-click > Duplicate) to create a duplicate copy of it. This is the same effect as placing a new instance, but quicker. You could do the same task through Quick Add or the Transformer Gallery if you desired.

Connect the second DensityEvaluator into the workflow, in parallel and not in series:

Two DensityEvaluators in parallel

3) Set Custom Transformer Parameters

By creating a second instance of the custom transformer we've started to re-use our content, which is great. However, the second instance is currently processing the wrong data.

Inspect the parameters for DensityEvaluator_2 and set the population parameter to TotalPopulation2011 (not 2001):

Choosing an attribute as a parameter for the DensityEvaluator

4) Run Workspace

Run the workspace and inspect the output to ensure the data is being processed correctly.

One obvious problem with the output from the transformer is that the result is put into an attribute called PopulationDensity2001, regardless of what data is being processed.

This is not useful; for example, the 2011 results also get the same name, as would any other scenario where we used this transformer. We should improve this by making the output name more generic.

5) Edit Custom Transformer

Click on the tab labeled DensityEvaluator to switch the canvas to the custom transformer definition. Inspect the ExpressionEvaluator_2001 parameters. Change the Transformer name to ExpressionEvaluator since we are processing more than just 2001 data. Then change the name of the Result parameter to DensityResult:

Configuring the ExpressionEvaluator

If you run the workspace again (run it from at least the custom transformer onwards) you’ll notice that DensityResult is the attribute output by both instances of the custom transformer; i.e., one edit has fixed both of them!

6) Rename Ports

We should also change the custom transformer's port names. At the moment they are not very elegant.

Back within the DensityEvaluator tab, click the cogwheel icon of the input port object (currently labeled AreaCalculator_Input). Inspect its parameters and change the Transformer Input Name to Input.

Now repeat the process for the output port object, renaming Transformer Output Name to Output:

Changing transformer port names

Click the Main tab to check back on the main canvas and confirm the changes have been made:

Edited custom transformers

You'll need to manually resize the transformers to fit their new naming style, as in the above image.

Challenge

You'll need this image to answer the first quiz question.

Image for quiz: GeometryFilter:Line to LengthCalculator, GeometryFilter:Area to AreaCalculator, LengthCalculator:Output and AreaCalculator:Output to o StatisticsCalculator. Three transformers (not GeometryFilter) are highlighted with arrows.